<template>
  <login type="login" :teleportRegister="register" :handleLogin="login" />
</template>

<script lang="ts">
import { defineComponent, ref, inject } from "vue";
import { useRouter } from "vue-router";
import { useUserStore } from "@/store/user/userStore";
import Login from "@/components/login/Login.vue";

export default defineComponent({
  components: {
    Login,
  },
  setup() {
    const router = useRouter();
    const userStore = useUserStore();

    const register = () => {
      router.push("/register");
    };
    const tip: any = inject("tip");

    const login = async (payload, rawDate, loginBox) => {
      const { email, password } = payload;
      try {
        await userStore.login(email, password);
        router.push("/");
      } catch (error: any) {
        tip({ to: loginBox, content: error.message });
      }
    };

    return {
      register,
      login,
    };
  },
});
</script>

